(function() {
  $(function() {
    var form;
    form = $('form.main');
    form.form({
      inline: true,
      fields: {
        t40_amt: {
          optional: false,
          rules: [
            {
              type: 'empty'
            }, {
              type: 'regExp[/^-?[0-9,.]+$/]'
            }
          ]
        },
        pay_chnl: {
          optional: false,
          rules: [
            {
              type: 'empty'
            }
          ]
        },
        pay_merid: {
          optional: false,
          rules: [
            {
              type: 'empty'
            }
          ]
        },
        acct_no: {
          optional: false,
          rules: [
            {
              type: 'empty'
            }
          ]
        },
        retrefno: {
          optional: false,
          rules: [
            {
              type: 'maxLength[12]'
            }, {
              type: 'minLength[12]'
            }
          ]
        }
      }
    });
    if (form.attr('action').endsWith('check')) {
      $('body').css('background-color', 'black');
    }
    return form.find('button#ok').click(function() {
      if (!form.form('is valid')) {
        return;
      }
      if ($(this).hasClass('clicked')) {
        $(this).removeClass('clicked red').addClass('green').text('确 定');
        return form.submit();
      } else {
        return $(this).removeClass('green').addClass('clicked red').text('确认追付');
      }
    });
  });

}).call(this);
